package com.zsw.alancomicserver.repository;

import com.zsw.alancomicserver.repository.po.BookPO;
import com.zsw.alancomicserver.repository.rowMapper.BookRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class BookRepository {

    @Resource
    private JdbcTemplate jdbcTemplate;

    public int insert(BookPO bookPO) {
        String sql = "insert into book(book_id, book_img, create_time, update_time, book_name, author) values(?,?,?,?,?,?)";
        return jdbcTemplate.update(sql, bookPO.getBookId(), bookPO.getBookImg(), bookPO.getCreateTime(), bookPO.getUpdateTime(),
                bookPO.getBookName(), bookPO.getAuthor());
    }

    public BookPO queryByBookId(Long bookId) {
        String sql = "select * from book where book_id=?";
        return jdbcTemplate.queryForObject(sql, new BookRowMapper(), bookId);
    }

    public List<BookPO> queryAll() {
        String sql = "select * from book";
        return jdbcTemplate.query(sql, new BookRowMapper());
    }
}
